home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- from __future__ import division
- import os
- import sys
- import tempfile
- import Image
- import ImageDraw
- import ImageFont
- import ImageEnhance
- import ImageOps
- import ImageStat
- import BmpImagePlugin
- import JpegImagePlugin
- import PngImagePlugin
- Image._initialized = 2
- from spamexperts import Version
-
- def annotate_splash(original, destination):
- text = 'v%s' % (Version.versions['Apps']['SpamExperts']['Product Version'],)
- annotate(original, text, destination, 'Arial.ttf', 8, (255, 255, 255))
-
-
- def professional_splash(name, address, code, original, destination):
- text = 'v%s' % (Version.versions['Apps']['SpamExperts']['Product Version'],)
- annotate(original, text, destination, 'Arial.ttf', 8, (255, 255, 255))
- annotate(destination, name, destination, 'Arial.ttf', 9, (229, 189, 63), 70, True)
- annotate(destination, address, destination, 'Arial.ttf', 9, (229, 189, 63), 55, True)
- annotate(destination, code, destination, 'Arial.ttf', 9, (229, 189, 63), 40, True)
-
-
- def annotate(image, text, destination, font = None, size = 10, colour = (0, 0, 0), distance_from_bottom = 22, centre = True):
- ''' Annotate an image with some text and save it to destination.
-
- - `image`: full path of source image, as a string
- - `text` : the string to paste on the image
- - `destination` : full path of image to save, as a string
- - `font` : full path of .pil bitmap font to use
-
- w
- <--------------------------->
- ^ +---------------------------+
- | | |
- | | |
- | | |
- h | | (w0,h0) |
- | | +---------+ |
- | | |some text| | |-> hb
- | | +---------+(w1,h1) | |-> fromBottomPixels
- v +---------------------------+
- l l
- <------> <------->
- <--------->
- wb
- '''
- fromBottomPixels = distance_from_bottom
- if font:
- font = ImageFont.truetype(font, size)
- else:
- font = ImageFont.load_default()
- img = Image.open(image)
- draw = ImageDraw.Draw(img)
- (wb, hb) = font.getsize(text)
- (w, h) = img.size
- if centre:
- w0 = int((w - wb) / 2)
- else:
- w0 = 10
- h0 = h - hb - fromBottomPixels
- w1 = w0 + wb
- h1 = h0 + hb
- draw.text((w0, h0), text, font = font, fill = colour)
- (fd, fn) = tempfile.mkstemp('.jpg')
- os.fdopen(fd).close()
- img.save(fn)
- bmp = Image.open(fn)
- bmp.save(destination)
- os.remove(fn)
-
-